﻿using System;
using System.Collections.Generic;
using System.Text;
using OneMG.Phoenix.Service.Contracts;
using OneMG.Phoenix.Service.Model;
using OneMG.Phoenix.IBatisRepository;
using OneMG.Phoenix.Respository;
using System.Data;
using OneMG.Phoenix.Entity;

namespace OneMG.Phoenix.Service
{
    public class RightsTypeService : IRightsTypeService
    {
		 IRightsType rightsType = new RightsTypeRepository();
		 
        public System.Int32 AddRightsType(RightsTypeModel model)
        {
			ERightsType entity = ConvertModelToEntity(model);
			
            return rightsType.AddRightsType(entity);
        }

		public void UpdateByTypeID (RightsTypeModel model)
		{
			ERightsType entity = ConvertModelToEntity(model);

            rightsType.UpdateByTypeID(entity);

		}

		public void DeleteByTypeID (System.Int32 typeID)
		{
		
            rightsType.DeleteByTypeID(typeID);

		}
		 
        public RightsTypeModel GetByTypeID (System.Int32 typeID)
        {
        
			ERightsType entity = rightsType.GetByTypeID(typeID);
			
            RightsTypeModel model = ConvertEntityToModel(entity);


            return model;
        }


        public IList<RightsTypeModel> GetAll()
        {
            IList<ERightsType> entityList = rightsType.GetAll();
            if (entityList == null)
                return null;

            IList<RightsTypeModel> modelList = new List<RightsTypeModel>();

            foreach (var item in entityList)
            {
                RightsTypeModel model = ConvertEntityToModel(item);
                modelList.Add(model);
            }

            return modelList;
        }

        
		public RightsTypeModel ConvertEntityToModel(ERightsType entity)
		{
			if (entity == null)
            {
                return null;
            }
			RightsTypeModel model = new RightsTypeModel();
                        model.TypeID = entity.TypeID;
                        model.TypeName = entity.TypeName;
                        model.ParentTypeID = entity.ParentTypeID;
                        model.SystemFlag = entity.SystemFlag;
                        model.CreateTime = entity.CreateTime;
                        model.CreateUser = entity.CreateUser;
                        model.UpdateTime = entity.UpdateTime;
                        model.UpdateUser = entity.UpdateUser;
                        return model;
		}
		
		public ERightsType ConvertModelToEntity(RightsTypeModel model)
		{
			if (model == null)
            {
                return null;
            }
			ERightsType entity = new ERightsType();
                        entity.TypeID = model.TypeID;
                        entity.TypeName = model.TypeName;
                        entity.ParentTypeID = model.ParentTypeID;
                        entity.SystemFlag = model.SystemFlag;
                        entity.CreateTime = model.CreateTime;
                        entity.CreateUser = model.CreateUser;
                        entity.UpdateTime = model.UpdateTime;
                        entity.UpdateUser = model.UpdateUser;
                        return entity;
		}
    }
}